package com.lw.yygh.hosp.controller.api;

import com.lw.yygh.hosp.service.DepartmentService;
import com.lw.yygh.hosp.service.HospService;
import com.lw.yygh.hosp.service.HospSetService;
import com.lw.yygh.hosp.service.ScheduleService;
import com.lw.yygh.model.hosp.Hospital;
import com.lw.yygh.model.order.SignInfoVo;
import com.lw.yygh.result.Result;
import com.lw.yygh.vo.hosp.DepartmentVo;
import com.lw.yygh.vo.hosp.HospitalQueryVo;
import com.lw.yygh.vo.hosp.ScheduleOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;

//前台api
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospApiController {
    @Autowired
    private HospService hospService;
    @Autowired
    private DepartmentService departmentService;
    @Autowired
    private ScheduleService scheduleService;
    @Autowired
    private HospSetService hospSetService;
    //医院列表(条件分页查询)
    @GetMapping("/list/{page}/{limit}")
    public Result listHosp(@PathVariable("page") String page,
                           @PathVariable("limit") String limit,
                           HospitalQueryVo hospitalQueryVo) throws UnsupportedEncodingException {
        Page<Hospital> hospitalPage=hospService.findHospPage(Integer.parseInt(page),Integer.parseInt(limit),hospitalQueryVo);
        return Result.ok( hospitalPage );
    }
    //根据医院名称进行模糊查询 返回list集合 有多个
    @GetMapping("/findByHosName/{hosname}")
    public Result findByHosName(@PathVariable String hosname){
        List<Hospital> hospital = hospService.findByHosname(hosname);
        return Result.ok( hospital );
    }
    //根据医院编号查询科室
    @GetMapping("/department/{hoscode}")
    public Result index(@PathVariable String hoscode){
        List<DepartmentVo> deptTree = departmentService.findDeptTree( hoscode );
        return Result.ok( deptTree );
    }
    //根据医院编号获取医院详情
    @GetMapping("/findHospDetail/{hoscode}")
    public Result item(@PathVariable String hoscode){
        Map<String,Object> map = hospService.item(hoscode);
        return Result.ok( map );
    }

    ///获取可预约排班数据
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @PathVariable String hoscode,
            @PathVariable String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode));
    }

    //获取排班数据
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @PathVariable String hoscode,
            @PathVariable String depcode,
            @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(hoscode, depcode, workDate));
    }

    //根据排班id获取排班数据
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(
            @PathVariable String scheduleId) {
        return Result.ok(scheduleService.getById(scheduleId));
    }

    //根据排班id获取预约下单数据
    @GetMapping("/inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    //获取医院签名信息
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @PathVariable("hoscode") String hoscode) {
        return hospSetService.getSignInfoVo(hoscode);
    }
    //删除订单后更新医院排班数据
    @GetMapping("/inner/updateSchedule/{scheduleId}")
    public void updateSchedule(@PathVariable String scheduleId){
        scheduleService.updateSchedule(scheduleId);
    }
}
